#include <game/services/Text.h>
#include <xml/Object.h>
#include <text/Dictionary.h>
#include <map>

namespace liba {
namespace resource {
class Resource;
} // namespace resource
} // namespace liba

ARELLO_GAME_NAMESPACE_DECL_START

struct Section
{
	Section() { }
	Section(const Section& rhs)
		: data(rhs.data)
	{ }
	const Section& operator=(const Section& rhs)
	{
		if (this != &rhs)
			this->data = rhs.data;
		return *this;
	}

	std::map<liba::Atom, std::wstring> data;
};

struct Chapter
{
	Chapter() { }
	Chapter(const Chapter& rhs)
		: data(rhs.data)
	{ }
	const Chapter& operator=(const Chapter& rhs)
	{
		if (this != &rhs)
			this->data = rhs.data;
		return *this;
	}

	std::map<liba::Atom, Section> data;
};

class TextServiceImpl
	: public services::Text
	, private liba::text::Dictionary
{
public:
	TextServiceImpl();
	~TextServiceImpl();

	bool ReadFrom(liba::resource::Resource* r);
private: // TextServiceImpl
	virtual const std::wstring& GetText(
		const liba::Atom& chapter, 
		const liba::Atom& section,
		const liba::Atom& id)
	{
		return this->DoGetText(chapter, section, id);
	}
protected: // services::Text
	virtual const std::wstring& DoGetText(
		const liba::Atom& chapter, 
		const liba::Atom& section,
		const liba::Atom& id);
private:
	std::map<liba::Atom, Chapter> data;
};

ARELLO_GAME_NAMESPACE_DECL_END